﻿using Client.Entity;
using Client.IBLL;
using Client.IDAL;
using System;
using System.Threading.Tasks;

namespace Client.BLL {
  public class LoginBLL :ILoginBLL{
    ILoginDAL _loginDAL;
    public LoginBLL(ILoginDAL loginDAL) {
      _loginDAL = loginDAL;
    }

    public async Task<bool> Login(string username, string password) {
      var loginStr = await _loginDAL.Login(username, password);
      //用户信息的反序列化
      UserEntity userEntity = Newtonsoft.Json.JsonConvert.DeserializeObject<UserEntity>(loginStr);
      if (userEntity != null) {
        GlobalEntity.CurrentUserInfo = userEntity;
        return true;
      }
      return false;
    }
  }
}
